<template>
    <div style="min-width: 809px">
        <div v-if="$route.path == '/projectComment'">
            <div class="vs-search-box">
                <!-- <div class="vs-table-box"> -->
                <el-form v-search-box-enter ref="form" :inline="true" :model="paging" label-width="110px">
                    <el-form-item label="评论时间：">
                        <el-date-picker v-model="paging.create_time" type="daterange" value-format="yyyy-MM-dd"
                            range-separator="至" start-placeholder="开始日期" style="width: 250px" end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="订单编号：">
                        <el-input style="width: 250px" v-model="paging.out_trade_no" placeholder=""></el-input>
                    </el-form-item>
                    <el-form-item class="vs-right-btns">
                        <el-button @click="reset(1)">重置</el-button>
                        <el-button @click="handleCurrentChange(1)" type="primary">查询</el-button>
                    </el-form-item>
                    <el-form-item label="项目名称：">
                        <el-input style="width: 250px" v-model="paging.name" placeholder=""></el-input>
                    </el-form-item>
                    <el-form-item label="用户名称：">
                        <el-input style="width: 250px" v-model="paging.username" placeholder=""></el-input>
                    </el-form-item>
                </el-form>
                <!-- </div> -->
            </div>
            <div class="vs-table-box">
                <el-table border :data="tableData" style="width: 100%">
                    <el-table-column type="index" label="序号" width="55px" align="center"> </el-table-column>
                    <el-table-column prop="create_time" label="评论时间" width="170" align="center"> </el-table-column>
                    <el-table-column prop="ordersIntegralGoods.orders.out_trade_no" label="订单编号" show-overflow-tooltip
                        align="center"> </el-table-column>
                    <el-table-column prop="project.name" label="服务项目名称" align="center" show-overflow-tooltip>
                    </el-table-column>
                    <!-- <el-table-column prop="reserveProject.reserve.name" label="用户名称" align="center" show-overflow-tooltip>
                    </el-table-column> -->
                    <el-table-column prop="user.username" label="用户名称" align="center" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column prop="project_score" label="评论星级" sortable align="center"> </el-table-column>
                    <el-table-column prop="content" label="评论内容" align="center" min-width="160" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column label="操作" width="200">
                        <template slot-scope="scope">
                            <div>
                                <el-button @click="setRow(1, scope.row)" type="text">查看</el-button>
                                <el-button @click="changeComment('status', 0, scope.row)" v-if="scope.row.status == 1"
                                    type="text">隐藏</el-button>
                                <el-button @click="changeComment('status', 1, scope.row)" v-else
                                    type="text">显示</el-button>
                                <el-button @click="changeComment('is_top', 0, scope.row)" v-if="scope.row.is_top == 1"
                                    type="text">取消置顶</el-button>
                                <el-button @click="changeComment('is_top', 1, scope.row)" v-else
                                    type="text">置顶</el-button>
                                <el-button @click="setRow(2, scope.row)" type="text">快捷回复</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="vs-paging-box">
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page.sync="paging.page" :page-size="paging.limit"
                        layout="total, sizes, prev, pager, next, jumper" :total="paging.total"
                        :page-sizes="[100, 200, 500, 1000]"> </el-pagination>
                </div>
            </div>
        </div>
        <router-view></router-view>
        <el-dialog title="快捷回复" :close-on-click-modal="false" :visible.sync="dialogVisible" width="400px"
            :before-close="dialogBeforeClose" style="text-align: center">
            <div class="dialog_body">
                <el-input type="textarea" v-model="reply_content" :rows="4" placeholder=""></el-input>
            </div>
            <div slot="footer" style="margin-top: 20px">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button :loading="isBtn" type="primary" @click="setGoodsComment">
                    {{ replyRow.reply_content ? '重新回复' : '确 定' }}
                </el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
    data() {
        return {
            reply_content: '',
            replyRow: {},
            keys: '',
            form: {
                bill_time_start: '',
                mode: '',
            },
            paging: {
                create_time: "",
                out_trade_no: "",
                name: "",
                username: "",
                page: 0,
                limit: 100,
                total: 0,
            },
            isBtn: false,
            dialogVisible: false,
            tableData: [],
        };
    },
    created() {
        if (this.$route.path == '/projectComment') {
            this.goodsComment();
        }
    },
    filters: {},
    methods: {
        async setGoodsComment() {
            let reply_content = this.reply_content.trim();
            if (!reply_content) return this.$message.error('请输入要回复的内容');
            if (reply_content === this.replyRow.reply_content) return this.$message.error('重新回复的内容不能与上次一致');
            this.isBtn = true;
            let { code, data } = await this.$Http.projectsetComment({
                reply_content,
                id: this.replyRow.id,
            });
            this.isBtn = false;
            if (code) {
                this.$message.success('回复成功!');
                this.dialogVisible = false;
                this.handleCurrentChange(1);
            }
        },
        setRow(type, row) {
            if (type == 1) {
                this.utils.goUrl('/projectCommentInfo?type=2&id=' + row.id);
            } else {
                this.replyRow = row;
                this.dialogVisible = true;
                this.reply_content = row.reply_content || '';
            }
        },
        async goodsComment() {
            let obj = Object.assign({}, this.paging);
            if (obj.create_time && obj.create_time.length) {
                obj.end_time = obj.create_time[1];
                obj.create_time = obj.create_time[0];
            } else {
                obj.create_time = '';
                obj.end_time = '';
            }
            this.loading = true;
            let { code, data } = await this.$Http.projectgetComment(obj);
            this.loading = false;
            if (code) {
                this.tableData = data.data;
                this.paging.total = data.total;
            }
        },
        async changeComment(type, value, row) {
            let keys = {
                //is_top （1：是 0：否） 隐藏 ： status（1：否 0：是）
                is_top: ['取消置顶', '置顶'],
                status: ['隐藏', '显示'],
            };
            this.$msgbox({
                title: '提示',
                message: `确定要${keys[type][value]}该评论吗?`,
                type: 'warning',
                showCancelButton: true,
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                beforeClose: async (action, instance, done) => {
                    if (action === 'confirm') {
                        instance.confirmButtonLoading = true;
                        instance.confirmButtonText = '执行中...';
                        let { code, data } = await this.$Http.projectchangeComment({
                            id: row.id,
                            field: type,
                            value,
                        });
                        if (code) {
                            this.$message.success('操作成功!');
                            this.handleCurrentChange(1);
                        }
                        done();
                        instance.confirmButtonLoading = false;
                    } else {
                        done();
                    }
                },
            })
                .then((action) => { })
                .catch(() => { });
        },
        reset() {
            //重置
            this.paging = this.$options.data().paging;
            this.handleCurrentChange(1);
        },
        dialogBeforeClose() {
            this.dialogVisible = false;
        },
        handleSizeChange(val) {
            this.paging.limit = val;
            this.goodsComment();
        },
        handleCurrentChange(val) {
            this.paging.page = val;
            this.goodsComment();
        },
    },
};
</script>

<style lang="scss" scoped>
::v-deep {
    .el-dialog__body {
        padding: 10px 20px;
        border-top: 1px solid rgba($color: #000000, $alpha: 0.2);
    }
}

.image-thumbnail {
    width: 130px;
    height: 130px;
}

.dialog_body {
    display: flex;
    flex-direction: column;
    text-align: left;

    >div:first-child {
        margin: 10px 0;
    }

    .d_body {
        display: flex;
        border: 1px solid rgba($color: #000000, $alpha: 0.1);
        padding: 10px;

        >div:last-child {
            display: flex;
            flex-direction: column;
            margin: 0 20px;

            // .ipt_body {
            //   width: 250px ;
            //   height: 100px;
            //     border: 1px solid rgba($color: #000000, $alpha: .3);

            // }

            >div:last-child {
                margin-top: 20px;
                text-align: right;
            }
        }
    }
}
</style>
